<template>
	<view class="payment-pages">
		<view class="payment-block">
			<view class="title FZHZGBJ">购买消费券</view>
			<view class="payment-info">
				<view class="payment-list" v-for="(item,index) in list" :key="item.id"
					:class="tabActive===item.id ? 'active':''" @click="changeActive(item.id,index)">
					<text class="price FZHZGBJ">{{item.quota}}</text>
					<text>券</text>
				</view>
			</view>
			<text class="payment-text1">更多金额</text>
			<view class="form-item">
				<view class="unit">￥</view>
				<input placeholder="请输入充值金额" v-model="price" class="form-crl" type="number" maxlength="6"
					@focus="changeInput" />
			</view>
			<text class="payment-text">支付相应的金额后，系统将为您自动发放益联券</text>
		</view>
		<view class="btn-item">
			<button class="payment-button" @click="payment">
				<text style="color: #FFFFFF;">充值</text>
			</button>
		</view>
		<view class="payment-block1">
			<view class="title FZHZGBJ">购买记录</view>
			<template v-if="infolist.length>0">
				<view class="record-list" v-for="item in infolist" :key="item.id">
					<view class="name-item">
						<view class="name">+{{item.amount}} 券</view>
						<view class="count">支付 {{item.amount}} 元</view>
					</view>
					<view class="time" style="margin-top: 15rpx;">支付时间：{{item.buyTime}}</view>
				</view>
			</template>
			<view class="empty" v-else>暂无数据</view>
		</view>
	</view>
</template>

<script>
	import {
		recharge,
		getList
	} from '@/api/bank.js';
	import {
		getUserInfo
	} from '@/api/home.js';
	export default {
		data() {
			return {
				list: [{
					id: 1,
					quota: 50
				}, {
					id: 2,
					quota: 100
				}, {
					id: 3,
					quota: 200
				}, {
					id: 4,
					quota: 300
				}, {
					id: 5,
					quota: 500
				}, {
					id: 6,
					quota: 1000
				}],
				infolist: [{
						id: 1,
						name: '+30券',
						price: '30.00',
						creatTime: '2024-08-25 14:31'
					},
					{
						id: 2,
						name: '+30券',
						price: '30.00',
						creatTime: '2024-08-20 16:48'
					}
				],
				tabActive: 0,
				payMoney: 0,
				changePrice: 0,
				price: '',
			}
		},
		methods: {
			getList() {
				getList({}).then(res => {
					this.infolist = res
				})
			},
			payment(e) {
				let that = this
				recharge({
					money: this.price
				}).then(res => {
					let appId = res.appId;
					let timeStamp = res.timeStamp;
					let nonceStr = res.nonceStr;
					let signType = res.signType;
					let paySign = res.paySign;
					let prepayId = res.prepayId;
					let prePayParams = res.prePayParams;
					uni.requestPayment({
						provider: 'wxpay',
						timeStamp: timeStamp,
						nonceStr: nonceStr,
						package: res.package,
						signType: 'MD5',
						paySign: paySign,
						success(res) {
							uni.showToast({
								title: '充值成功',
								duration: 2000,
								mask: true,
							})
							that.getList();
							//that.getUser();
						}
					});
				})
			},
			changeActive(e, index) {
				this.tabActive = e
				this.changePrice = this.list[index].quota
				this.price = this.changePrice
			},
			// getUser() {
			// 	getUserInfo().then((res) => {
			// 		if (res.vip == 1) {

			// 		}
			// 	})
			// },
			changeInput() {
				this.tabActive = 0;
				this.changePrice = 0;
			},
		},
		onLoad(e) {
			this.getList()
		}
	}
</script>

<style lang="scss" scoped>
	.payment-pages {
		overflow: hidden;
		min-height: 100vh;
		background-color: #F5F5F5;

		.top-block {
			padding: 180rpx 30rpx 20rpx 30rpx;
			background-image: linear-gradient(to bottom, #3153B6, #4173E7);

			.info-block {
				background: #FFFFFF;
				padding: 30rpx;
				border-radius: 20rpx;

				.title {
					margin-bottom: 30rpx;
					font-size: 32rpx;
				}

				.price-item {
					display: flex;
					align-items: center;
					color: #4376E4;
					font-size: 28rpx;
					margin-bottom: 20rpx;

					.price {
						font-size: 44rpx;
						margin-right: 10rpx;
					}
				}

				.info-item {
					display: flex;
					font-size: 30rpx;
					line-height: 65rpx;

					.name {
						width: 160rpx;
						color: #767676;
					}

					.text {
						width: calc(100% - 160rpx);
					}
				}
			}
		}

		.payment-button {
			width: 288px;
			height: 50px;
			border-radius: 50px;
			opacity: 1;
			background: linear-gradient(90deg, #FF2F34 0%, #FF6B18 100%);
			box-shadow: 0px 4px 10px 0px rgba(0, 0, 0, 0.1);
		}

		.payment-block1 {
			width: calc(100% - 60rpx);
			margin: 30rpx auto;

			.title {
				font-family: Microsoft YaHei;
				font-weight: bold;
				font-size: 32rpx;
				margin-bottom: 30rpx;
			}

			.record-list {
				background-color: #FFFFFF;
				margin-bottom: 30rpx;
				padding: 30rpx;
				border-radius: 20rpx;

				.name-item {
					display: flex;
					align-items: center;
					justify-content: space-between;
					font-size: 30rpx;

					.name {
						font-family: Microsoft YaHei;
						font-size: 16px;
						font-weight: normal;
						line-height: 22px;
						letter-spacing: 0px;
						font-variation-settings: "opsz" auto;
						/* 正文色/正文色 */
						color: #1A1A1A;
					}

					.count {
						font-family: Microsoft YaHei;
						font-size: 16px;
						font-weight: normal;
						line-height: 22px;
						text-align: right;
						letter-spacing: 0px;

						/* 主色 */
						color: #FF2F34;
					}
				}

				.time {
					color: #767676;
					font-family: Microsoft YaHei;
					font-size: 14px;
					font-weight: normal;
					line-height: 22px;
					letter-spacing: 0px;
				}
			}
		}

		.payment-block {
			width: calc(100% - 60rpx);
			margin: 20rpx auto;
			background-color: #FFFFFF;
			padding: 30rpx;
			border-radius: 20rpx;

			.title {
				font-family: Microsoft YaHei;
				font-weight: bold;
				font-size: 32rpx;
				margin-bottom: 30rpx;
			}

			.payment-info {
				display: flex;
				align-items: center;
				flex-wrap: wrap;
				margin-top: 30rpx;

				.payment-list:nth-child(3n) {
					margin-right: 0;
				}

				.payment-list.active {
					background: linear-gradient(90deg, #FF2F34 0%, #FF6B18 100%);
					color: #FFFFFF;
				}

				.payment-list {
					width: calc((100% - 40rpx) / 3);
					margin-right: 20rpx;
					margin-bottom: 20rpx;
					background: #ffffff;
					padding: 24rpx 30rpx;
					display: flex;
					border: 1px solid red;
					align-items: center;
					justify-content: center;
					border-radius: 15rpx;
					font-size: 30rpx;
					color: #FF2F34;
				}
			}

			.payment-text {
				width: 354px;
				height: 18px;
				opacity: 1;
				font-family: Microsoft YaHei;
				font-size: 14px;
				font-weight: normal;
				line-height: normal;
				letter-spacing: 0em;
				/* 正文色/正文辅助色 */
				color: #767676;
			}

			.payment-text1 {
				font-family: Microsoft YaHei;
				font-size: 16px;
				font-weight: normal;
				line-height: normal;
				letter-spacing: 0em;

				/* 正文色/正文色 */
				color: #1A1A1A;
			}

			.form-item {
				display: flex;
				align-items: center;
				justify-content: space-around;
				border-bottom: 1px solid #F7F7F7;
				line-height: 90rpx;
				font-size: 30rpx;

				.unit {
					font-weight: bold;
					margin-right: 10rpx;
				}

				.form-crl {
					width: calc(100% - 100rpx);
				}

				.iconfont {
					color: #767676;
					font-size: 34rpx;
				}
			}

			.btn-item {
				display: flex;
				justify-content: center;
				margin-top: 40rpx;
			}
		}
	}
</style>